package com.bear.cmcc.NetTestHTTP.util;

import com.bear.cmcc.NetTestHTTP.component.CityBean;

import java.util.Comparator;

@SuppressWarnings("rawtypes")
public class SortCityIntSpeed implements Comparator{
	public final static int signalStrength=0x0010;
	public final static int electricalLevel=0x0020;
	public final static int droppingRate=0x0030;
	public final static int UP = 1;
    public final static int DOWN = -1;
    private int state;
    private int flag;
   
    /**
     * 2G排序
     * @param state 排序状态值
     */
    public SortCityIntSpeed(int state,int flag) {
        this.state = state;
        this.flag=flag;
    }
    
	public int compare(Object obj1, Object obj2) {
		CityBean ps1 = (CityBean)obj1;
		CityBean ps2 = (CityBean)obj2;
		if (state == SortCityIntSpeed.DOWN) {
			switch(flag){
				case signalStrength:
					return sortDonw(ps1.signalStrength, ps2.signalStrength);
//				case electricalLevel:
//					return sortDonw(ps1.electricalLevel, ps2.electricalLevel);
				case droppingRate:
					return sortDonw(Integer.valueOf(ps1.droppingRate.replaceAll("%", "")), Integer.valueOf(ps2.droppingRate.replaceAll("%", "")));
			}
		}	
		switch(flag){
			case signalStrength:
				return sortUp(ps1.signalStrength, ps2.signalStrength);
//			case electricalLevel:
//				return sortUp(ps1.electricalLevel, ps2.electricalLevel);
		}
		return sortUp(Integer.valueOf(ps1.droppingRate.replaceAll("%", "")), Integer.valueOf(ps2.droppingRate.replaceAll("%", "")));
	}
	
	/**
	 * 升序
	 * @param sp1
	 * @param sp2
	 * @return
	 */
	private int sortUp(int sp1,int sp2)
	{
		if(sp1 < sp2)
			return -1;
		else if(sp1 > sp2)
			return 1;
		else
			return 0;
	}
	
	/**
	 * 降序
	 * @param sp1
	 * @param sp2
	 * @return
	 */
	private int sortDonw(int sp1,int sp2)
	{
		if(sp1 > sp2)
			return -1;
		else if(sp1 < sp2)
			return 1;
		else
			return 0;
	}

}
